package com.example.myys.data.repository

import com.example.myys.Constants
import com.example.myys.MyApplication
import com.example.myys.data.InventoryDatabase
import com.example.myys.data.entity.DataBean
import com.example.myys.network.HtmlClient

class MusicRepository {
    val htmlClient = HtmlClient
    val musicDao= InventoryDatabase.getInstance(MyApplication.instance).dataBeanDao()
    val TYPE= Constants.YY
    val SOURCE_NAME="Yy"

    //获取音乐推荐
    suspend fun getMusicRecommend():List<DataBean>?{
        val musicList=htmlClient.getRecommend(SOURCE_NAME,"")
        return musicList
    }
    //搜索音乐
    suspend fun getMusicByKeyword(keyword:String):List<DataBean>?{
        return htmlClient.getSearchByKeword(SOURCE_NAME,keyword)
    }
    //加入收藏
    suspend fun addMusicShelf(dataBean:DataBean){
        dataBean.type=TYPE
        val id=musicDao.insert(dataBean)
    }
    //获取收藏
    suspend fun getMusicShelf():List<DataBean>{
        return musicDao.getListByType(TYPE)
    }

    //获取播放
    suspend fun getMusicPlayUrl(ids: String): String? {
        return htmlClient.getChapterContent(SOURCE_NAME, ids)
    }

}